package com.heima.admin.listener;

import com.heima.admin.service.NewsAutoScanService;
import com.heima.common.constants.admin.NewsAutoScanConstants;
import jdk.nashorn.internal.ir.IfNode;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author Ronaldo
 * @date 2021/8/8
 */
@Component
public class NewsAutoScanListener {

    @Autowired
    private NewsAutoScanService newsAutoScanService;

    @KafkaListener(topics = NewsAutoScanConstants.WM_NEWS_AUTO_SCAN_TOPIC)
    public void autoScan(ConsumerRecord<String,String> consumerRecord){
        Optional<ConsumerRecord<String, String>> optional = Optional.ofNullable(consumerRecord);
        optional.ifPresent(record ->  newsAutoScanService.newsAutoScanById(Integer.valueOf(record.value())));
    }
}
